@extends('layouts.header')
@section('style')
    .icheckbox-blue {
    top: 2px;
    }

    .check-box {
    padding-left: 21px;
    }

    #label_danwei {
    line-height: 30px;
    height: 30px;
    }
@endsection
@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 检测业务 <span
            class="c-gray en">&gt;</span> <a href="javascript:;"
                                             onclick="location.href='/{{config('constant.name_admin')}}/contract/indexAll';">批次查看</a>
        <span class="c-gray en">&gt;</span> 编辑
        <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:window.location.reload();" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
        <a class="btn btn-primary radius r mr-10" style="line-height:1.6em;margin-top:3px"
           href="javascript:self.location=document.referrer;">
            <i class="Hui-iconfont Hui-iconfont-arrow1-left"></i>&nbsp;&nbsp;返回
        </a>
    </nav>

    <div class="page-container">
        <div class="panel panel-primary">
            <div class="panel-header">样品添加</div>
            <div class="panel-body">
                <form class="form form-horizontal" id="form" autocomplete="off">
                    <input type="hidden" name="client_id" value="{{ $client_info->id }}">
                    <input type="hidden" name="client_name" value="{{ $client_info->name }}">

                    <div class="row cl">
                        <label class="form-label col-sm-1">样品名称：</label>
                        <div class="formControls col-sm-3">
                            <select class="select2" id="sample_name" name="tool_id" style="width: 100%">
                                <option value="" selected disabled>--请选择--</option>
                                @foreach($tool_info as $val)
                                    <option value="{{$val -> id}}">{{$val -> name}}</option>
                                @endforeach
                            </select>
                        </div>

                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">检验标准：</label>
                        <div class="formControls col-sm-3">
                            <select class="select2" name="std_id" id="std_id" style="width: 100%">
                                {{-- <option value="" disabled>--请选择--</option> --}}
                            </select>
                        </div>
                        <label class="form-label col-sm-1">额定电压：</label>
                        <div class="formControls col-sm-3">
                            <select class="select2" name="vol_id" style="width: 100%">
                                {{-- <option value="" disabled>--请选择--</option> --}}
                            </select>
                        </div>
                        <label class="form-label col-sm-1">分类：</label>
                        <div class="formControls col-sm-3">
                            <select class="select2" name="class_id" style="width: 100%">
                                {{-- <option value="" disabled>--请选择--</option> --}}
                            </select>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">检验项目：</label>
                        <div class="formControls col-sm-11">
                            <div class="panel panel-default">
                                <div class="panel-body">
                                    <div id="test_items" class="skin-minimal">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">条形码：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="" placeholder="" id="bar_code" name="bar_code" >
                        </div>
                        <label class="form-label col-sm-1">样品自编号：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="{{old('self_num')}}" placeholder="" name="self_num" id="self_num">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">规格型号：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="{{old('guige_xinghao')}}" placeholder=""
                                   name="guige_xinghao" id="guige_xinghao">
                        </div>
                        <label class="form-label col-sm-1">商标：</label>
                        <div class="formControls col-sm-2">
                            <input type="text" class="input-text" value="{{old('brand')}}" placeholder="" name="brand"
                                   id="brand">
                        </div>
                        <label class="form-label col-sm-1">生产厂家：</label>
                        <div class="formControls col-sm-2">
                            <select class="select2" id="facturer" style="width: 100%">
                                <option value="">--请选择--</option>
                                @foreach ($factorys as $val)
                                    <option value="{{ $val }}"
                                            @if(old('manufacturer') === $val) selected @endif> {{ $val }} </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="formControls col-sm-2">
                            <input type="text" class="input-text" value="{{old('manufacturer')}}" placeholder="这里可以填写生产厂家"
                                   name="manufacturer" id="manufacturer">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">生产日期：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" id="production_date" name="production_date" value="{{old('production_date')}}" class="input-text">
                        </div>
                        <label class="form-label col-sm-1">样品状态：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="外观无异常" placeholder="" name="sample_status"
                                   id="sample_status">
                        </div>

                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">检测地点：</label>
                        <div class="formControls col-sm-11" id="place">
                            @if($places)
                                @foreach($places as $i => $item)
                                    <div class="radio-box">
                                        <input @if($i===0) checked @endif name="place" id="radio-{{$i}}" type="radio"
                                               value="{{$item}}">
                                        {{-- <label for="radio-{{$i}}">{{$item}}</label>--}}
                                        <span for="radio-{{$i}}">{{$item}}</span>
                                        <i onclick="test_place_op('del','{{$item}}','radio-{{$i}}')"
                                           class="Hui-iconfont">&#xe6e2;</i>
                                    </div>
                                @endforeach
                            @endif
                            <div class="radio-box">
                                <input name="place" id="ziding" type="radio" value="">
                                <span for="ziding">自定义检测地点：
                                    <input onclick="check()" id="test_place" class="inline input-text " maxlength="9"
                                           type="text" placeholder="自定义检测地点">
                                    <input onclick="test_place_op('add')" id="test_place_add"
                                           class="btn btn-primary-outline hidden" type="button" value="添加到地点列表">
                                    <span style="color: red;">*</span>最长9个汉字或数字
                                </span>
                            </div>
                        </div>
                    </div>
                    @csrf
                    <input type="hidden" name="is_scan" value="0">

                    <div class="form form-horizontal ">
                        <div class="row cl">
                            <label class="form-label col-sm-1">强制报废日期：</label>
                            <div class="formControls col-sm-3">
                                <input type="text" id="force_scrap_date" name="force_scrap_date" value="" onfocus="WdatePicker({minDate:'%y-%M-%d'})" class="input-text Wdate">
                            </div>
                        </div>
                    </div>
                    <div class="row cl ">
                        <div class="text-c">
                            <input class="btn btn-primary radius mb-5" type="submit" value="&nbsp;&nbsp;添加&nbsp;&nbsp;">
                        </div>
                    </div>
                    @csrf
                </form>

                @foreach($tool_info as $val)
                    <span id="danwei{{$val -> id}}" hidden>{{$val -> unit}}</span>
                @endforeach

            </div>
        </div>

        <div class="panel panel-primary mt-15">
            <div class="panel-header">已添加样品</div>
            <div class="panel-body">
                <table class="table table-border table-bordered table-hover table-bg table-responsive table-condensed">
                    <thead>
                    <tr class="text-c">
                        <th>样品名称</th>
                        <th>额定电压</th>
                        <th>分类</th>
                        <th>检验标准</th>
                        <th>检验项目</th>
                        <th>单位</th>
                        <th>条形码范围</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <br>
                    @foreach ($data as $val)
                        <tr class="text-c">
                            <td class="tool_name">{{ $val->tool_name }}</td>
                            <td class="voltage">{{ $val->voltage }}</td>
                            <td id="class_{{$val->id}}" onclick="changeClass('{{$val->id}}','{{$val->tool_id}}','{{ $val->std_id }}')">{{ $val->voltage_class }}</td>
                            <td id="std_num_{{$val->id}}">{{ $val->std_num }}</td>
                            <td class="item_names">{{ $val->item_names }}</td>
                            <td>{{ $val->unit }}</td>
                            <td class="bar_codes">{{ $val->bar_code }}</td>
                            <td class="f-14">
                                <a title="删除" href="javascript:;" onclick="del(this,'{{ $val->id }}')" class="ml-5"
                                   style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    {{--    必须加H-ui.js，不然有问题--}}
    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.js"></script>



    <script type="text/javascript">

        $(function () {

            $('.select2').select2({
                language: "zh-CN"
            });
            var index2;
            $('select[name=vol_id]').on('change', function () {
                let voltext = $('select[name=vol_id] option:checked').text();
                var reg = new RegExp("{vol}", "g");//g,表示全部替换。
            })
            /*+1 -1效果*/
            $("#spinner-demo").Huispinner({
                name: 'count',
                value: 1,
                minValue: 1,
                maxValue: 500,
                dis: 1
            });

            function isCount(s) {//是否为正整数 首尾可包含空白字符
                var re = /^\s*[1-9]\d*\s*$/;
                return re.test(s)
            }

            //在选择样品类型后列出 检验标准、单位
            $('#sample_name').change(function () {
                //获取当前样品类型id
                var id = $(this).val();

                //在追加之前先清除之前的数据
                $('select[name=std_id]').find('option').remove();//标准
                $('select[name=vol_id]').find('option').remove();//额定电压
                $('select[name=class_id]').find('option').remove();//分类
                $('#test_items').html('');//项目
                $('#label_danwei').html('');//单位

                if (id > 0) {
                    //================= 单位 ===================
                    var danwei = $('#danwei' + id).html();
                    $('#label_danwei').html(danwei);
                    $.get('/{{config('constant.name_admin')}}/myapi/getStdParam', {id: id}, function (data) {
                        //================= 检验标准 ===================
                        str = '';
                        $.each(data.data_std, function (index, el) {
                            str += "<option value='" + el.id + "'>" + el.num + "</option>";
                        });
                        var temp = str;
                        if (str == '') {
                            str = "<option value=''>无</option>";
                        }
                        //将数据放到对应的option之后
                        $('select[name=std_id]').append(str);

                        //================= 触发 检验标准的 change 事件 ===================
                        if (temp != '') {
                            $("select[name=std_id]").trigger("change");
                        }
                    }, 'json');
                }
            });

            /* 在选择检验标准后列 出检测项目、额定电压、分类 */
            $('#std_id').change(function () {
                //获取当前检验标准id
                var std_id = $(this).val();
                //获取当前工器具id
                var tool_id = $('#sample_name').val();

                //在追加之前先清除之前的的数据
                $('select[name=vol_id]').find('option').remove();//额定电压
                $('select[name=class_id]').find('option').remove();//分类
                $('#test_items').html('');//项目

                if (std_id > 0) {
                    $.get('/{{config('constant.name_admin')}}/myapi/getItem', {
                        std_id: std_id,
                        tool_id: tool_id
                    }, function (data) {
                        //================= 额定电压 ===================
                        var str = '';
                        $.each(data.data_vol, function (index, el) {
                            str += "<option value='" + el.id + "'>" + el.val + "</option>";
                        });
                        if (str == '') {
                            str = "<option value='0'>无</option>";
                        }
                        //将数据放到对应的option之后
                        $('select[name=vol_id]').append(str);
                        let voltext = $('select[name=vol_id] option:checked').text();
                        var reg = new RegExp("{vol}", "g");//g,表示全部替换。

                        //================= 分类 ===================
                        str = '';
                        $.each(data.data_class, function (index, el) {
                            str += "<option value='" + el.id + "'>" + el.val + "</option>";
                        });
                        if (str == '') {
                            str = "<option value='0'>无</option>";
                        }
                        //将数据放到对应的option之后
                        $('select[name=class_id]').append(str);

                        //================= 项目 ===================
                        str = '';
                        $.each(data.data_item, function (index, el) {
                            str += "<div class='check-box'><label><input type='checkbox' checked name='items[]' value='" + el.id + "'>" + el.name + "</label></div>";
                        });
                        //将数据放到对应的option之后
                        $('#test_items').html(str);
                        $('.skin-minimal input').iCheck({
                            checkboxClass: 'icheckbox-blue',
                            radioClass: 'iradio-blue',
                            increaseArea: '20%'
                        });
                    }, 'json');
                }
            });

            //layer弹窗的索引，关闭layer时要用到
            var index2;
            $("#form").validate({
                rules: {
                    // tool_id:{
                    // 	required:true,
                    // },
                    // vol_id:{
                    // 	required:true,
                    // },
                    // class_id:{
                    // 	required:true,
                    // },
                    // std_id:{
                    // 	required:true,
                    // },
                    // items:{
                    // 	required:true,
                    // },
                    // count:{
                    // 	required:true,
                    // 	isPoInteger:true,
                    // 	max:500,
                    // },
                },
                // onkeyup:false,
                // focusCleanup:false,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "/{{config('constant.name_admin')}}/client/insert_gqj",//自己提交给自己可以不写url
                        // data:{
                        // 	sample_name : $('#sample_name').find("option:selected").text(),
                        // 	biaozhun : $('#biaozhun').find("option:selected").text(),
                        // 	danwei : $('#label_danwei').html(),
                        // },

                        //beforeSend  beforeSubmit
                        beforeSubmit: function () {
                            //如果验证不通过，返回false，阻止表单提交
                            var sample_name = $('#sample_name').val();
                            // console.log(sample_name);
                            var biaozhun = $('#std_id').val();
                            var l = $("#test_items input:checked").length;
                            var bar_code = $('#bar_code').val();
                            var self_num = $('#self_num').val();
                            var guige_xinghao = $('#guige_xinghao').val();
                            var production_date = $('#production_date').val();
                            var sample_status = $('#sample_status').val();
                            var force_scrap_date = $('#force_scrap_date').val();

                            if (sample_name == null) {
                                layer.msg('样品名称不能为空', {time: 2000});
                                return false;
                            } else if (biaozhun == "") {
                                layer.msg('检验标准不能为空1', {time: 2000});
                                return false;
                            } else if (l == 0) {
                                layer.msg('检验项目不能为空', {time: 2000});
                                return false;
                            } else if (bar_code == "") {
                                layer.msg('条形码不能为空', {time: 2000});
                                return false;
                            } else if (self_num == "") {
                                layer.msg('自编号不能为空', {time: 2000});
                                return false;
                            } else if (guige_xinghao == "") {
                                layer.msg('规格型号不能为空', {time: 2000});
                                return false;
                            } else if (production_date == "") {
                                layer.msg('生产日期不能为空', {time: 2000});
                                return false;
                            } else if (sample_status == "") {
                                layer.msg('样品状态不能为空', {time: 2000});
                                return false;
                            } else if (force_scrap_date == "") {
                                layer.msg('强制报废日期不能为空', {time: 2000});
                                return false;
                            }
                        },
                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {shade: [0.3, '#fff']});
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                        success: function (data) {
                            //判断添加结果
                            if (data === '1') {
                                window.location.reload();//刷新
                                // parent.table_reload(0);//0停留在当前页，1回到第一页
                                parent.layer.msg('添加成功!', {icon: 1, time: 2000});
                            } else {
                                // layer.msg(data, { icon: 2, time: 2000 });
                                layer.open({
                                    content: data,
                                    title: false,
                                    type: 0,
                                    icon: 5,
                                    // skin: 'layui-layer-molv',
                                    btn: '',
                                    closeBtn: 2, //右上角关闭按钮风格  0无,1默认,2
                                    shadeClose: true, //开启遮罩关闭
                                    time: 0,
                                    anim: 6,//弹出动画
                                });
                            }
                        },
                        error: function (data) {
                            ajax_error(data);
                        }
                    });
                }
            });

        });

        $('#test_place').bind('input propertychange', function () {
            let val = $(this).val();
            if (val) {
                $("#test_place_add").removeClass('hidden');
                $("input[type='radio']:checked", '#place').val(val);
            }
            val ? $("#test_place_add").removeClass('hidden') : $("#test_place_add").addClass('hidden');
        })

        function test_place_op(func='add', val = '', id = '') {
            val = func === 'add' ? $('#test_place').val() : val;
            if ($.trim(val) !== '') {
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/setting/testPlace/' + func + '/' + val,
                    success: function (res) {
                        let str = func === 'add' ? '添加' : '删除';
                        if (res === '1') {
                            layer.msg(str + '成功');
                            if (func === 'add') {
                                str = '<div class="radio-box">\n' +
                                    '                                    <input name="place" id="radio-{{time()}}" type="radio" value="' + val + '">\n' +
                                    '                                    <label for="radio-{{time()}}">' + val + '</label>\n' +
                                    '                                    <i onclick="test_place_op(\'del\',\'' + val + '\',\'radio-{{time()}}\')" class="Hui-iconfont">&#xe6e2;</i>\n' +
                                    '                                </div>'
                                $('#ziding').parent('.radio-box').before(str);
                            } else {
                                $('#' + id).parent('.radio-box').remove();
                            }
                        } else {
                            layer.msg(str + '失败');
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.05, '#000']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });
            }
        }

        function check() {
            $(':input[type=radio]', '#place').removeAttr('checked');
            $('#ziding').trigger('click');
        }

        function addItem(id, std_id, tool_id, obj) {
            $.get('/{{config('constant.name_admin')}}/myapi/getItem', {
                std_id: std_id,
                tool_id: tool_id
            }, function (data) {
                data = data.data_item;
                let item_names = '，' + $(obj).closest('tr').find('td.item_names').text() + '，',
                    content = '<div class="text-c"><div class="col-sm-10"><select class="input-text " name="add_item_id" style="width: 100%">',
                    item_name = '', optionItem = 0;
                for (index in data) {
                    item_name = '，' + data[index].name + '，';
                    if (item_names.indexOf(item_name) === -1) {
                        optionItem = 1;
                        content += '<option value="' + data[index].id + '">' + item_name.trim('，') + '</option>';
                    }
                }
                if (optionItem === 0) {
                    layer.msg('没有可以增加的项目了！');
                    return;
                }
                content += ' </select></div> <br> <br> <a class="btn btn-primary radius" onclick="addItemSub(' + id + ',' + tool_id + ')">确定</a></div>';
                layer.open({
                    type: 1,
                    area: ['300px', '200px'],
                    shade: 0.4,
                    title: '添加检验项目',
                    content: content,
                });
            }, 'json');
        }

        //确定添加检验项目
        function addItemSub(id, tool_id) {
            let data = {};
            data.id = id;
            data.item_id = $('select[name=add_item_id]').val();
            data.tool_id = tool_id;
            ajax('post', 'addItem', data, '');
        }

        //切换标准
        function changeStd(id, stdid, toolid) {
            let param = {
                std_id:stdid,
                tool_id:toolid,
            };
            ajax('get', 'changeStd', param, back,0);

            function back(data) {
                if (data === '0') {
                    layer.msg('请求错误！');
                    return false;
                }
                if (data.length === 0) {
                    layer.msg('没有可以切换的标准！');
                    return false;
                }
                let content = '<div class="text-c"><div class="col-sm-10"><select class="input-text " name="to_std_id" style="width: 100%">';
                for (index in data) {
                    content += '<option value="' + data[index].std_id + '">' + data[index].num + '</option>';
                }
                content += ' </select></div> <br> <br> <a class="btn btn-primary radius" onclick="changeStdSub(' + id + ',' + stdid + ',' + toolid + ')">确定</a></div>';
                layer.open({
                    type: 1,
                    area: ['300px', '200px'],
                    shade: 0.4,
                    title: '切换标准',
                    content: content,
                });
            }
        }

        //确定切换标准
        function changeStdSub(id, stdid, toolid) {
            let data = {}, param = {};
            param.id = id;
            param.std_id = stdid;
            param.to_std_id = $('[name=to_std_id]').val();
            param.tool_id = toolid;
            param._token = '{{csrf_token()}}';
            data.param = param;
            ajax('post', 'changeStd', data, back1);

            function back1(res) {
                if (res === '0') {
                    layer.msg('请求错误！');
                    return false;
                } else if (res === '1') {
                    layer.msg('切换成功！');
                    $('#std_num_' + id).text($('[name=to_std_id]').text());
                    return false;
                } else {
                    layer.msg(res);
                    return false;
                }
            }
        }

        /*删除*/
        function del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/client/gqj_del' + '?id=' + id,
                    // dataType: 'json',
                    success: function (data) {
                        // console.log(data);
                        if (data === '1') {
                             layer.msg('删除成功!',{icon:1,time:2000});
                        } else {
                            layer.msg('删除失败!', {icon: 2, time: 2000});
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.05, '#000']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });
            });
        }

        /*编辑*/
        function edit(id, column, e) {

            let value = '';
            let msg = '';
            if (column === 'count') {
                msg = '请输入减少后的数量:';
                value = $(e).text();
            }
            layer.prompt({
                    title: msg,
                    value: value
                }, function (rescount, index, elem) {
                    let resnum = Number(rescount);
                    let valnum = Number(value);
                    // layer.close(index);
                    let errormsg = '';
                    if (column === 'count') {
                        errormsg = resnum > valnum ? '请直接进行样品添加' : resnum < 1 ? '数量不能小于1' : '';
                        if (valnum === resnum) {
                            return false;
                        }
                    }
                    if (errormsg != '') {
                        layer.alert(errormsg);
                        return false;
                    }
                    $.ajax({
                        type: 'GET',
                        url: 'edit/' + id + '?' + column + '=' + resnum,
                        success: function (data) {
                            if (data === '1') {
                                let barcodes = $(e).siblings('.bar_codes').text();
                                movebarcode(id, valnum, resnum, barcodes);
                            } else {
                                layer.msg('编辑失败!', {icon: 2, time: 2000});
                            }
                        },
                        error: function (data) {
                            ajax_error(data);
                        },
                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {shade: [0.05, '#000']});
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                    })

                }
            )


        }


        /*管理员-角色-添加*/
        function admin_role_add(title, url, w, h) {
            layer_show(title, url, w, h);
        }

        /*管理员-角色-修改*/
        function admin_role_edit(title, url, id, w, h) {
            layer_show(title, url + '?id=' + id, w, h);
        }

        function barcode_set() {
            var title = '条形码设置';
            var url = '/{{config('constant.name_admin')}}/setting/printBarCodeSet';
            var w = 800;
            var h = 500;
            layer_show(title, url, w, h);
        }

        function movebarcode(id, valnum, resnum, barcodes) {
            layer.confirm('是否要将最后的条形码迁移至此，保持编码连续性？', {
                icon: 1,
                title: '确认操作',
                btn: ['确定', '取消'],
                btn1: function (index) {
                    let numcha = valnum - resnum;
                    $.ajax({
                        type: 'GET',
                        url: 'ajaxEditBarcode/' + id + '/' + numcha + '/' + barcodes + '?contract_id=' + '{{request()->get('id')}}',
                        success: function (data) {
                            if (data === '1') {
                                parent.layer.msg('操作成功!', {icon: 1, time: 2000});
                            } else {
                                parent.layer.msg(data, {icon: 2, time: 2000});
                            }
                            window.location.reload();//刷新
                        },
                        error: function (data) {
                            ajax_error(data);
                        },
                    })
                },
                btn2: function (index) {
                    window.location.reload();//刷新
                }
            });
        }

        function changeClass(id, toolid, stdid) {
            let data = {}, param = {};
            param.std_id = stdid;
            param.tool_id = toolid;
            data.param = param;
            ajax('get', '/{{config('constant.name_admin')}}/myapi/getItem', data, changeClassBack);

            function changeClassBack(data) {
                if (data.data_class.length === 0) {
                    layer.msg('没有可以更新的分类！');
                    return false;
                }
                //================= 分类 ===================
                let content = '<div class="text-c"><div class="formControls col-sm-8">\n' +
                    '               <select class="input-text" name="class_id1" style="width: 100%">\n';
                $.each(data.data_class, function (index, el) {
                    content += "<option value='" + el.id + "'>" + el.val + "</option>";
                });
                content += ' </select></div> <br> <br> <a class="btn btn-primary radius" onclick="changeClassSub(' + id + ')">确定</a></div>';
                layer.open({
                    type: 1,
                    area: ['300px', '200px'],
                    shade: 0.4,
                    title: '修改分类',
                    content: content,
                });
            }

        }

        function changeClassSub(id) {
            let data = {}, param = {};
            param.class_id = $('[name=class_id1]').val();
            param.class = $('[name=class_id1] option:checked').text();
            param.id = id;
            param._token = '{{csrf_token()}}';
            data.param = param;
            ajax('post', 'changeClass', data, changeClassSubBack);

            function changeClassSubBack(res) {
                if (res === '0') {
                    layer.msg('修改失败！');
                    return false;
                } else if (res === '1') {
                    layer.msg('修改成功！');
                    $('#class_' + id).text(param.class);
                    return false;
                } else {
                    layer.msg(res);
                    return false;
                }
            }
        }

        $('#getThirdGqj').on('click',function () {
            // body...
            console.log(11111111);
            ajax('get','getThirdGqj','',getThirdGqjBak);
            function getThirdGqjBak(res) {
                console.log();
            }
        })
    </script>
@endsection
